package core.heuristic;

import java.util.Set;

import core.course.Course;
import core.course.TimeTable;
import core.interfaces.IState;
import core.interfaces.IUtility;

public abstract class HeuristicBase implements IUtility<IState<TimeTable>, Double>
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 349074555653822683L;

	protected boolean isCoursesCollide(TimeTable timeTable)
	{
		return timeTable.isCoursesCollide();
	}
	
	protected boolean isCourseRelevant(TimeTable timeTable, Course course)
	{
		Set<Course> adjacents = course.getAdjacentsCourses();
		
		boolean courseRelevant = true; 
		for(Course adj : adjacents)
		{
			if(!timeTable.isCourseExist(adj))
			{
				courseRelevant = false;
			}
			
		}
		return courseRelevant;
	}
	
	protected double spaces(TimeTable timeTable)
	{
		return (double)timeTable.freeTime();
	}
	
	protected double fair(TimeTable timeTable)
	{
		int[] diffPartition = timeTable.difficultyPartition();
		double fair = 1.0;
		for(int i=0; i < timeTable.getMaxDifficulty(); ++i)
		{
			if(diffPartition[i] != 0)
			{
				fair *= (1/diffPartition[i]);				
			}
		}
		return fair;
	}
	
	protected double collision(TimeTable timeTable)
	{
		return (0-timeTable.collisionNumber());
	}
}
